#include <vector>
#include<array>
#include <string>

class Solution {
public:
    int lengthOfLongestSubstring(std::string s) {
        if (s.empty()) return 0;
        std::array<int,256> ss;
        ss.fill(-1);
        int n = s.size();
        int ans = -1;
        for (int r = 0,l = 0;r<n;r++)
        {
            l = std::max(l,ss[s[r]]+1);
            ss[s[r]] = r;
            ans = std::max(ans, r-l+1);
        }
        return ans;
    }
};

